<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      姓：<input type="text" v-model="firstName" /> <br />
      名：<input type="text" v-model="lastName" /> <br />
      <p>姓名: {{ fullName }}</p>
      姓名: <input type="text" v-model="fullName" />
    </div>
    <script src="./js/vue.js"></script>
    <script>
      const vm = new Vue({
        data: {
          firstName: "",
          lastName: "",
        },
        computed: {
          // 只读的计算属性(不能更新)
          // fullName() {
          //   return this.firstName + " " + this.lastName;
          // },
          // 可读可写的计算属性
          fullName: {
            // 属性读取方法
            get() {
              console.log("get()");
              return this.firstName + " " + this.lastName;
            },
            // 属性设置/更新方法
            set(val) {
              console.log("set()", val);
              // 数组的解构赋值
              const [firstName, lastName] = val.split(" ");
              this.firstName = firstName;
              this.lastName = lastName;
            },
          },
        },
      });
      vm.$mount("#app");
    </script>
  </body>
</html>
